<template>
	<view class="applyAdmin-con">
		<view v-if="isAdmin === 1">已是管理员</view>
		<view v-else>
			<view class="userData">
				<view class="user-item">姓名：{{ userData.username || '' }}</view>
				<view class="user-item">学院：{{ userData.colleges || '' }}</view>
				<view class="user-item">电话：{{ userData.phoneNum || '' }}</view>
				<view class="user-item">学号：{{ userData.schollNum || '' }}</view>
				<view class="user-item">专业：{{ userData.professional || '' }}</view>
				<view class="user-item">班级/年级：{{ userData.gradeAndClassInfo || '' }}</view>
				<view class="user-item">角色：{{ userData.jiaoses || '' }}</view>
			</view>
			
			<button style="margin-top: 40rpx;" type="primary" @click="apply" :loading="isLoading">确认申请</button>
		</view>
	</view>
</template>

<script>
	import { applyAdmin } from "../../network/users.js"
	import { mapState } from 'vuex'
	export default {
		data() {
			return {
				isAdmin:0,
				isLoading:false,
				userData:""
			}
		},
		onLoad() {
			if(this.userInfo.type === "admin"){
				this.isAdmin = 1;
			} else {
				this.userData = this.userInfo;
			}
			
		},
		methods: {
			apply(){
				this.isLoading = true;
				applyAdmin(this.userData).then(res=>{
					if(res.data.code === 1){
						this.isLoading = false;
					}
				}).catch(err=>{
					
				})
			}
			
		},
		computed:mapState([
			'userInfo'
		])
	}
</script>

<style lang="scss">
	.applyAdmin-con{
		padding-left: 20rpx;
		padding-right: 20rpx;
	}
	.userData{
		margin-top: 20rpx;
		background: #FFFFFF;
		box-shadow: 0 0 12px #CCCCCC;
		.user-item{
			height: 60rpx;
			line-height: 60rpx;
			border-bottom: 1px solid #CCCCCC;
		}
	}
</style>
